<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>收银</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button id="add" button data-method="offset" data-type="auto"  class="layui-btn layui-btn-lg layui-btn-primary layui-border-blue"> 扫码 </button>
                <button id="recede" button data-method="offset" data-type="recede" class="layui-btn layui-btn-lg layui-btn-primary layui-border-red">退货</button>
                <button style="float: right" class="layui-btn layui-btn-lg layui-btn-primary layui-border-red">结算</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>


        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">取消购买</a>
        </script>


        <%--        审批状态--%>
        <script type="text/html" id="examineTpl">
            {{#  if(d.manager === 0){ }}
            <span style="color: #9ACD32;">经理未审批</span>
            {{#  } else if(d.manager === 1&&d.payment===0){ }}
            <span style="color: #ADFF2F;">店长未审批</span>
            {{#  } else if(d.manager === 1&&d.payment === 1){ }}
            <span style="color: #7CFC00;">同意购买</span>
            {{#  } else if(d.manager === 1&&d.payment === 2){ }}
            <span style="color: #00FF00;">已付款</span>
            {{#  } }}
        </script>


        <%--        保管员接收状态--%>
        <script type="text/html" id="receiveTpl">
            {{#  if(d.receive === 1){ }}
            <span style="color: #02DF82;">核对完成</span>
            {{#  } else { }}
            未接收
            {{#  } }}
        </script>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../../../jquery-3.3.1.js" charset="UTF-8"></script>
<script>
    layui.use(['table','layer'], function () {
        var $ = layui.jquery,
            table = layui.table,
            layer = layui.layer;

        table.render({
             elem: '#currentTableId'
            ,url: '/log/checkoutList'
            ,toolbar: '#toolbarDemo'
            ,escape: true
            ,totalRow: true
            , cols: [[
                {width:20},
                {field: 'cid', Width:100, title: '商品编号', sort: true},
                {field: 'cname', minWidth:1, title: '商品名称'},
                {field: 'tname',minWidth:1, title: '商品类型'},
                {field: 'sprice', minWidth:1, title: '售价',templet:function (d) {
                        return d.sprice+'元/'+d.mlittle
                    }},
                {field: 'quantity', minWidth:1, title: '购买数量', sort: true,templet:function (d) {
                        return d.quantity+d.mlittle
                    }},
                {field: 'expense',minWidth:1, title: '所需金额', sort: true,templet:function (d) {
                        return (d.sprice*d.quantity).toFixed(2)+'元'
                    }},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]]
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('确认放弃购买么', function (index) {
                    $.post(
                        "/log/checkoutDel",{
                            cid:data.cid
                        },function () {
                            layer.close(index)
                            location.reload()
                        }
                    )
                });
            }
        });
        //触发事件
        var quit = {
            offset: function(othis){
                var type = othis.data('type')
                    ,text = othis.text();

                layer.open({
                    title:'请输入退回商品信息'
                    ,type: 1
                    ,offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                    ,id: 'layerDemo'+type //防止重复弹出
                    ,content: '<div style="padding: 20px 100px;">'+
                        '<div class="layui-form-item">\n' +
                        '        <label class="layui-form-label required">商品编号</label>\n' +
                        '        <div class="layui-input-block">\n' +
                        '            <input id="delsid" type="number" name="sid" lay-verify="required" value="" class="layui-input">\n' +
                        '        </div>\n' +
                        '    </div>' +
                        '<div class="layui-form-item">\n' +
                        '        <label class="layui-form-label required">退回数量</label>\n' +
                        '        <div class="layui-input-block">\n' +
                        '            <input id="delquantity" type="number" name="quantity" lay-verify="required" lay-reqtext="所含个数不能为空" placeholder="请输入所含个数" value="" class="layui-input">\n' +
                        '        </div>\n' +
                        '    </div>'+
                        '</div>'
                    ,btn: '退货'
                    ,btnAlign: 'r' //按钮居中
                    ,shade: 0 //不显示遮罩
                    ,yes: function(){
                        $.post(
                            "/log/dellogInsert",{
                                delsid:$("#delsid").val(),
                                delquantity:$("#delquantity").val()
                            },function () {
                            }
                        )
                        layer.closeAll();
                        location.reload()
                    }
                });
            }
        };

        $('#add').on('click', function(){
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });

        var active = {
            offset: function(othis){
                var type = othis.data('type')
                    ,text = othis.text();

                layer.open({
                    type: 1
                    ,offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                    ,id: 'layerDemo'+type //防止重复弹出
                    ,content: '<div style="padding: 20px 100px;">'+
                        '<div class="layui-form-item">\n' +
                        '        <label class="layui-form-label required">商品编号</label>\n' +
                        '        <div class="layui-input-block">\n' +
                        '            <input id="sid" type="number" name="sid" lay-verify="required" lay-reqtext="所含个数不能为空" placeholder="请输入所含个数" value="" class="layui-input">\n' +
                        '        </div>\n' +
                        '    </div>' +
                        '<div class="layui-form-item">\n' +
                        '        <label class="layui-form-label required">购买数量</label>\n' +
                        '        <div class="layui-input-block">\n' +
                        '            <input id="quantity" type="number" name="quantity" lay-verify="required" lay-reqtext="所含个数不能为空" placeholder="请输入所含个数" value="" class="layui-input">\n' +
                        '        </div>\n' +
                        '    </div>'+
                        '</div>'
                    ,btn: '扫码完成'
                    ,btnAlign: 'c' //按钮居中
                    ,shade: 0 //不显示遮罩
                    ,yes: function(){
                        $.post(
                            "/log/checkoutAdd",{
                                sid:$("#sid").val(),
                                quantity:$("#quantity").val()
                            },function () {
                            }
                        )
                        layer.closeAll();
                        location.reload()
                    }
                });
            }
        };
        $('#recede').on('click', function(){
            var othis = $(this), method = othis.data('method');
            quit[method] ? quit[method].call(this, othis) : '';
        });

            $(document).on('keyup', function(e){
                if(e.keyCode === 32){
                    layer.prompt({
                        title:'请输入会员ID/手机号'
                        ,btn:'确认'
                        ,value:'无'
                        ,id: 1 //防止重复弹出
                    },function(val, index,elem){
                        $.post(
                            "/log/reduced",{
                                vid:elem.val()
                            },function (res) {
                                var id=null;
                                if (elem.val()=="无"){
                                    id=0
                                }else {
                                    id=elem.val()
                                }
                                var index = layer.open({
                                    title: '付款',
                                    type: 2,
                                    shade: 0.2,
                                    maxmin:true,
                                    shadeClose: true,
                                    area: ['100%', '100%'],
                                    content: 'payment.jsp?reduced='+res+"&&vid="+id,
                                    end:function () {
                                        location.reload();
                                    },
                                })
                                $(window).on("resize", function () {
                                    layer.full(index);
                                });

                            }
                        )
                        layer.close(index);
                    });

                }
            });

        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作

            }
        });


    });
</script>

</body>
</html>